// actrion创建函数 返回action，action即是带有type的普通对象
// action只是描述了发生的事情，并没有描述如何更新 state， 这一功能还要靠reducer

import { AddTodoType, RemoveTodoType } from './actionTypes'

export const addTodo = text => ({
    type: AddTodoType,
    text
})

export const removeTodo = id => ({
    type: RemoveTodoType,
    id
})

export const fetchTodo = id => 
(dispatch, getState) => {
    console.log(getState())
    return new Promise(resolve => {
        setTimeout(() => {
            dispatch(addTodo('fetch from server'))
            console.log(getState())
        }, 1000)
    })
}

